package chessman;

import java.util.ArrayList;

import javax.swing.ImageIcon;

public class Pawn  extends Chessman{
	/**
	 * 
	 */
	private static final long serialVersionUID = 3960940732431843235L;
	private static Pawn instanceA = new Pawn(new ImageIcon("Resources/Images/Pawn-icon.png"),0);
	private static Pawn instanceB = new Pawn(new ImageIcon("Resources/Images/Pawn-blue-icon.png"),1);
		public static Pawn getInstanceTeamA(){
			return instanceA;
		}
		public static Pawn getInstanceTeamB(){
			return instanceB;
		}
	public Pawn(ImageIcon icon, int team) {
		super(icon, team);
		// TODO Auto-generated constructor stub
	}

	@Override
	public ArrayList<String> canMove(Chessman[] arrayChess) {
		ArrayList<String> moves = new ArrayList<String>();
		String temp = null;
		Chessman c = null;
		
		if(  this.team == 0 ){ // team A tu duoi len
			if(this.row == 6){  // vi tri bat dau 
				for(int i = 1 ;i<3;i++){
					c = arrayChess[(this.row-i) * 8 + this.col]; 
					if( c == null){ //khong co can duong
							temp = this.cols[this.col]+this.rows[this.row - i];
							moves.add(temp);
							
					}
					else{
						break;
					}
				}
				
				
			}
			else{
					if(this.row - 1 >= 0){
					c = arrayChess[(this.row-1) * 8 + this.col]; 
					if( c == null){ //khong co can duong
							temp = this.cols[this.col]+this.rows[this.row - 1];
							moves.add(temp);
					}
					}
				
				
			}
			if(this.row - 1 >=0 && this.col - 1 >=0 ){
				c = arrayChess[(this.row-1) * 8 + this.col-1];
				if( c!= null && !this.isSameTeam(c)){
					temp = this.cols[this.col-1]+this.rows[this.row - 1];
					moves.add(temp);
				}
			}
			if(this.row - 1 >=0 && this.col + 1 < 8 ){
				c = arrayChess[(this.row-1) * 8 + this.col+1];
				if( c!= null && !this.isSameTeam(c)){
					temp = this.cols[this.col+1]+this.rows[this.row - 1];
					moves.add(temp);
				}
			}
		
		}
		else{// team B tu tren xuong
			if(this.row == 1){  // vi tri bat dau 
				for(int i = 1 ;i<3;i++){
					c = arrayChess[(this.row+i) * 8 + this.col]; 
					if( c == null){ // co can duong
							temp = this.cols[this.col]+this.rows[this.row + i];
							moves.add(temp);
					}
					else{
						break;
					}
						
				}
				
				
			}
			else{
				if(this.row + 1 < 8){
					c = arrayChess[(this.row+1) * 8 + this.col]; 
					if( c == null){ // co can duong
							temp = this.cols[this.col]+this.rows[this.row + 1];
							moves.add(temp);
					}
				}
				
			}
			if(this.row + 1 < 8 && this.col - 1 >=0 ){
				c = arrayChess[(this.row+1) * 8 + this.col-1];
				if( c!= null && !this.isSameTeam(c)){
					temp = this.cols[this.col-1]+this.rows[this.row + 1];
					moves.add(temp);
				}
			}
			if(this.row + 1 >=0 && this.col + 1 < 8 ){
				c = arrayChess[(this.row+1) * 8 + this.col+1];
				if( c!= null && !this.isSameTeam(c)){
					temp = this.cols[this.col+1]+this.rows[this.row + 1];
					moves.add(temp);
				}
			}
		}
		
		return moves;
	}

}
